package com.example.questionnaire.broadcastreceiver;

import android.content.BroadcastReceiver;
import android.content.Context;
import android.content.Intent;
import android.util.Log;
import android.widget.Toast;

import com.example.questionnaire.MainActivity;
import com.example.questionnaire.MyApplication;

/**
 * author: liweixing
 * date: 2018/1/9
 */

public class BootBroadcastReceiver extends BroadcastReceiver {
    //开机广播（从关闭电源到开机的过程）
//    public static final String action_boot = "android.intent.action.BOOT_COMPLETED";
    //注意这个action只能有系统发出，是在用户唤醒机器的时候才会发出这种action
//    public static final String action_user_present = "android.intent.action.USER_PRESENT";
//    //监听系统关闭广播（关闭电源的广播）
//    private static final String ACTION_SHUTDOWN = "android.intent.action.ACTION_SHUTDOWN";

    @Override
    public void onReceive(Context context, Intent arg1) {
        //这里是屏幕关闭后再打开屏幕的操作
        String action = arg1.getAction();
        if (Intent.ACTION_BOOT_COMPLETED.equals(action) || Intent.ACTION_USER_PRESENT.equals(action)) {
            if (!MyApplication.application.isStartOver()) {
                MyApplication.application.setStartOver(true);

                Intent ootStartIntent = new Intent(context, MainActivity.class);
                ootStartIntent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
                context.startActivity(ootStartIntent);
            }
        }
    }
}